//
//  WithdrawalsController.swift
//  newshaohuo
//
//  Created by shaohuo on 2018/3/14.
//  Copyright © 2018年 shaohuo. All rights reserved.
//

import Foundation
import SwiftProgressHUD

class WithdrawalsController: UITableViewController {
    
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var accountTextField: UITextField!
    
    @IBOutlet weak var moneyTextField: UITextField!
    
    @IBOutlet weak var balanceLabel: UILabel!
    
    var balanceStr = "0.00"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "提现"
        
        balanceLabel.text = balanceStr
    }
    
    
    @IBAction func confirmBtnAction(_ sender: UIButton) {
        
        requestWithdraw(realName: nameTextField.text!, zfbAccount: accountTextField.text!, amount: moneyTextField.text!)
    }
    
    //提现
    func requestWithdraw(realName:String,zfbAccount:String,amount:String) -> Void {
        
        if realName.isEmpty {
            SwiftProgressHUD.showOnlyText("请输入用户名")
            return
        }
        
        if zfbAccount.isEmpty {
            SwiftProgressHUD.showOnlyText("请输入账户名称")
            return
        }
        
        if amount.isEmpty||amount.hasPrefix(".") {
            SwiftProgressHUD.showOnlyText("请输入合法金额")
            return
        }
        
 
        //要加密的数据
        let param = ["command":"withdraw","token":UserTicketModel.sharedInstance.token,"uid":UserTicketModel.sharedInstance.uid,"zfbAccount":zfbAccount,"realName":realName,"amount":amount]
        
        NetworkTools.sharedInstance.postRequest(urlString: "", parameters: param as AnyObject, headers: ["copyright":"v1","interface":"UserInfo"], successed: { (resultDict) in
            
                SwiftProgressHUD.showOnlyText("提现成功")
                self.navigationController?.popViewController(animated: true)
            
        })
    }
}

extension WithdrawalsController {
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.001
    }
}
